<?php
require_once 'CMS/Util.php';
require_once 'CMS/Mvc/BaseController.php';
require_once 'CMS/Mvc/BaseUserController.php';
require_once 'CMS/UserCommon.php';
require_once 'CMS/User.php';
require_once 'CMS/Language.php';

//Người tạo : Nguyễn Huỳnh Đại Thành - Team 3
//Module 	: Support Online
//Chức năng	: Show ra tất cả những người có nhiệm vụ support online cho người dùng
 
class SupportOnline_IndexController{

	public function init(){
		parent::init();
	}

	//Action index thục hiện chức năng show thông tin của module
	public function indexAction(){
		/*========== Start Load Language ==========*/
		$language = new Language(APPLICATION_PATH . '/widgets/supportonline');
		if(isset($_SESSION['language']))
		{
			$language_id = $_SESSION['language'];
			$tbLanguage = new Language_Model_Language();
			$name = $tbLanguage->getNameLanguage($language_id);
			$language->load($name['name']);
		}
		else
			$language->load('Default');		
		/*========== End Load Language ==========*/
			
		/*========== Start Get Text ==============*/
		$this->view->textPhone 		= $language->get('text_phone');
		$this->view->textConfirm	= $language->get('text_confirm');
		/*========== End Text ==============*/		
		
		
		//Start------Khai báo các parameter
		$tbSupport = new SupportOnline_Model_Support();
		$path = APPLICATION_PATH."/widgets/supportonline/";
		$xmlconfig = new SimpleXMLElement($path."config.xml",null,true);//Read config.xml
		//End--------Khai báo các parameter
		
		//Start------Get Supporter
		$AllSupporter = $tbSupport->getAllSupporter();
		//End--------Get Supporter
		
		//Start------Truyền parameter qua View
		/************ Start check user login *********/
		$session = new Zend_Session_Namespace('login.auth');
    if(isset($session->id_user))
		{
			$this->view->login = "2";
			$this->view->user_name = $session->name_user;
			/************ Start check permission *********/
			$user = new User();
			$user->init();
			$hasmodify = $user->modifiy_widget($xmlconfig->name);
			$this->view->permission = $hasmodify;
			/************ End check user permission *********/
		}
		else 
		{
			
			$this->view->login = "0";
		}
		/************ End check user login *********/
		
		if(count($AllSupporter)>0)
		{
			
			$listsupport = array();
			foreach ($AllSupporter as $support){
			$pos = unserialize($support['support_position']);
			if(isset($pos[$name['name']]) && isset($name)){
				$position = $pos[$name['name']];
			}else{
				$position = $pos['Default'];
			}
			$listsupport[] = array(
									'suppord_id'	=>	$support['suppord_id'],
									'support_name'	=>	$support['support_name'],
									'support_position'	=>	$position,
									'phone'		=>	$support['phone'],
									'skype'		=>	$support['skype'],
									'yahoo'			=>	$support['yahoo']
								);
		}	
		$this->view->AllSupporter = $listsupport;	
		}
		else 
		{
			$this->view->AllSupporter = array();
		}
        $titleXML = 'title'.$name['name'];
        if(isset($xmlconfig->$titleXML))
        	$this->view->title = $xmlconfig->$titleXML;
        else
        	$this->view->title = $xmlconfig->titleDefault;
			//end---truyen title
		//End--------Truyền parameter qua View
	
	}
	
	
}